package com.aduerr.v1shouyin.mvp.adpter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.aduerr.v1shouyin.R;
import com.aduerr.v1shouyin.entity.MemberRechargeRecordEntity;
import com.aduerr.v1shouyin.mvp.activity.MemberRechargeDetailActivity;

import java.util.List;

/**
 * @author HI
 * @email dev1024@foxmail.com
 * @time 2019/5/27 16:31
 * @change
 * @chang time
 * @class describe
 */

public class MemberRechargeListAdapter extends RecyclerView.Adapter<MemberRechargeListAdapter.ViewHolder> {


    private Context context;
    private List<MemberRechargeRecordEntity.DataBean> lists;

    public MemberRechargeListAdapter(Context context,
                                     List<MemberRechargeRecordEntity.DataBean> lists) {
        this.context = context;
        this.lists = lists;
    }

    public void updateData(List<MemberRechargeRecordEntity.DataBean> lists) {
        this.lists = lists;
        notifyDataSetChanged();
    }

    public void addData(List<MemberRechargeRecordEntity.DataBean> lists) {
        for(MemberRechargeRecordEntity.DataBean lb : lists) {
            this.lists.add(lb);
        }
        notifyDataSetChanged();
    }

    public void clearData() {
        this.lists.clear();
        notifyDataSetChanged();
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        // 实例化展示的view
        View v =
                LayoutInflater.from(parent.getContext()).inflate(R.layout.item_refund_record, parent, false);
        // 实例化viewholder
        ViewHolder viewHolder = new ViewHolder(v);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(final ViewHolder holder, final int position) {
        MemberRechargeRecordEntity.DataBean dataBean = lists.get(position);
        holder.tvTime.setText((dataBean.getPayTime()));
        holder.tvState.setText(dataBean.getRechargeMoney());
        holder.tvOrderId.setText(dataBean.getGiveMoney());
        switch(dataBean.getPayType()) {
            case 0://现金
                holder.tvMoney.setText("现金");
                break;
            case 1://微信
                holder.tvMoney.setText("微信");
                break;
            case 2://支付宝
                holder.tvMoney.setText("支付宝");
                break;
            case 3://云闪付
                holder.tvMoney.setText("云闪付");
                break;
        }
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, MemberRechargeDetailActivity.class);
                intent.putExtra("orderid", dataBean.getOrderId());
                context.startActivity(intent);
            }
        });

    }

    @Override
    public int getItemCount() {
        return lists == null ? 0 : lists.size();
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {

        TextView tvTime, tvState, tvOrderId, tvMoney;

        public ViewHolder(View itemView) {
            super(itemView);
            tvTime = (TextView) itemView.findViewById(R.id.tv_time);
            tvState = (TextView) itemView.findViewById(R.id.tv_state);
            tvOrderId = (TextView) itemView.findViewById(R.id.tv_order_id);
            tvMoney = (TextView) itemView.findViewById(R.id.tv_money);
        }
    }
}
